package mblog.core.persist.service.impl;

import mblog.core.data.Addresses;
import mblog.core.data.AuthMenu;
import mblog.core.persist.dao.AddressesDao;
import mblog.core.persist.dao.AuthMenuDao;
import mblog.core.persist.entity.AddressesPO;
import mblog.core.persist.entity.AuthMenuPO;
import mblog.core.persist.service.AddressesService;
import mblog.core.persist.utils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional(readOnly = true)
@CacheConfig(cacheNames = "addressesCaches")
public class AddressesServiceImpl implements AddressesService {

    @Autowired
    private AddressesDao dao;

    @Override
    public List<Addresses> findByParentId(String parentId) {
        List<Addresses> resultList = new ArrayList<>();
        List<AddressesPO> dataList = dao.findAllByParentId(parentId);
        if(dataList!=null && dataList.size()>0){
            return BeanUtils.createBeanListByTarget(dataList,Addresses.class);
        }else{
            return null;
        }
    }
}
